package com.luanye.enjoy.controller;

import com.luanye.enjoy.entity.Activity;
import com.luanye.enjoy.enums.ResultCode;
import com.luanye.enjoy.service.ActivityService;
import com.luanye.enjoy.vo.RespBean;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.Objects;

@RestController
@RequestMapping("/community")
@AllArgsConstructor
public class CommunityController {

    private final ActivityService activityService;

    @GetMapping("/index/{openid}")
    public RespBean index(@PathVariable("openid") String openid) {
        return activityService.getIndex(openid);
    }

    @GetMapping("/getDetail/{id}/{openid}")
    public RespBean getDetail(@PathVariable("id") Long id, @PathVariable("openid") String openid) {
        return activityService.getDetail(id, openid);
    }

    @PostMapping("/activity/create/{openid}")
    public RespBean create(@RequestBody Activity activity, @PathVariable("openid") String openid){
        if (Objects.isNull(activity))
            return RespBean.error(ResultCode.VALIDATE_ERROR);
        return activityService.create(activity,openid);
    }

    @GetMapping("/{id}/{openid}")
    public RespBean delete(@PathVariable("id") Long id, @PathVariable("openid") String openid){
        return activityService.delete(id,openid);
    }
    @GetMapping("/search/{keyword}")
    public RespBean search(@PathVariable("keyword") String keyword){
        return activityService.search(keyword);
    }
    @GetMapping("/join/{id}/{openid}")
    public RespBean join(@PathVariable("id") Long id, @PathVariable("openid") String openid){
        return activityService.join(id,openid);
    }
    @GetMapping("/exit/{id}/{openid}")
    public RespBean exit(@PathVariable("id") Long id, @PathVariable("openid") String openid){
        return activityService.exit(id,openid);
    }
}
